Enter the directory of the maca folder on your drive and the name of the tissue you want to analyze.
tissue_of_interest = "Bladder"
Load the requisite packages and some additional helper functions.
library(here)
here() starts at /Users/olgabot/code/tabula-muris
library(useful)
Loading required package: ggplot2
library(Seurat)
Loading required package: cowplot
Attaching package: 'cowplot'
The following object is masked from 'package:ggplot2':
ggsave
Loading required package: Matrix
Warning: namespace 'Biobase' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'lme4' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'MatrixModels' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'Biobase' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'lme4' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
Warning: namespace 'MatrixModels' is not available and has been replaced
by .GlobalEnv when processing object 'call.'
library(dplyr)
Warning: package 'dplyr' was built under R version 3.4.2
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(Matrix)
save_dir = here('00_data_ingest', 'tissue_robj')
droplet_data_dir = here('00_data_ingest', '01_droplet_raw_data')
# read the metadata to get the plates we want
droplet_metadata_filename = here('00_data_ingest', '01_droplet_raw_data', 'metadata_droplet.csv')
droplet_metadata <- read.csv(droplet_metadata_filename, sep=",", header = TRUE)
colnames(droplet_metadata)[1] <- "channel"
droplet_metadata
Subset the metadata on the tissue.
tissue_metadata = filter(droplet_metadata, tissue == tissue_of_interest)[,c('channel','tissue','subtissue','mouse.sex', 'mouse.id')]
tissue_metadata
Use only the metadata rows corresponding to Bladder plates. Make a plate barcode dataframe to “expand” the per-plate metadata to be per-cell.
# Load the gene names and set the metadata columns by opening the first file
subfolder = paste0(tissue_of_interest, '-', tissue_metadata$channel[1])
raw.data <- Read10X(data.dir = here('00_data_ingest', '01_droplet_raw_data', 'droplet', subfolder))
colnames(raw.data) <- lapply(colnames(raw.data), function(x) paste0(tissue_metadata$channel[1], '_', x))
meta.data = data.frame(row.names = colnames(raw.data))
meta.data['channel'] = tissue_metadata$channel[1]
if (length(tissue_metadata$channel) > 1){
# Some tissues, like Thymus and Heart had only one channel
for(i in 2:nrow(tissue_metadata)){
subfolder = paste0(tissue_of_interest, '-', tissue_metadata$channel[i])
new.data <- Read10X(data.dir = here('00_data_ingest', '01_droplet_raw_data', 'droplet', subfolder))
colnames(new.data) <- lapply(colnames(new.data), function(x) paste0(tissue_metadata$channel[i], '_', x))
new.metadata = data.frame(row.names = colnames(new.data))
new.metadata['channel'] = tissue_metadata$channel[i]
raw.data = cbind(raw.data, new.data)
meta.data = rbind(meta.data, new.metadata)
}
}
rnames = row.names(meta.data)
meta.data <- merge(meta.data, tissue_metadata, sort = F)
row.names(meta.data) <- rnames
dim(raw.data)
[1] 23433 2500
corner(raw.data)
[1] 0 0 0 1 0
head(meta.data)
Process the raw data and load it into the Seurat object.
# Find ERCC's, compute the percent ERCC, and drop them from the raw data.
erccs <- grep(pattern = "^ERCC-", x = rownames(x = raw.data), value = TRUE)
percent.ercc <- Matrix::colSums(raw.data[erccs, ])/Matrix::colSums(raw.data)
ercc.index <- grep(pattern = "^ERCC-", x = rownames(x = raw.data), value = FALSE)
raw.data <- raw.data[-ercc.index,]
# Create the Seurat object with all the data
tiss <- CreateSeuratObject(raw.data = raw.data, project = tissue_of_interest,
min.cells = 5, min.genes = 5)
tiss <- AddMetaData(object = tiss, meta.data)
tiss <- AddMetaData(object = tiss, percent.ercc, col.name = "percent.ercc")
# Create metadata columns for annotations and subannotations
tiss@meta.data[,'annotation'] <- NA
tiss@meta.data[,'subannotation'] <- NA
Calculate percent ribosomal genes.
ribo.genes <- grep(pattern = "^Rp[sl][[:digit:]]", x = rownames(x = tiss@data), value = TRUE)
percent.ribo <- Matrix::colSums(tiss@raw.data[ribo.genes, ])/Matrix::colSums(tiss@raw.data)
tiss <- AddMetaData(object = tiss, metadata = percent.ribo, col.name = "percent.ribo")
A sanity check: genes per cell vs reads per cell.
GenePlot(object = tiss, gene1 = "nUMI", gene2 = "nGene", use.raw=T)
Filter out cells with few reads and few genes.
tiss <- FilterCells(object = tiss, subset.names = c("nGene", "nUMI"),
low.thresholds = c(500, 1000), high.thresholds = c(25000, 5000000))
Normalize the data, then regress out correlation with total reads
tiss <- NormalizeData(object = tiss)
tiss <- ScaleData(object = tiss, vars.to.regress = c("nUMI", "percent.ribo","Rn45s"))
[1] "Regressing out nUMI" "Regressing out percent.ribo"
[3] "Regressing out Rn45s"
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 12%
|
|======== | 13%
|
|========= | 14%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 16%
|
|=========== | 17%
|
|=========== | 18%
|
|============ | 18%
|
|============ | 19%
|
|============= | 20%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 23%
|
|=============== | 24%
|
|================ | 24%
|
|================ | 25%
|
|================= | 26%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|===================== | 32%
|
|====================== | 33%
|
|====================== | 34%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 43%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 47%
|
|=============================== | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 51%
|
|================================== | 52%
|
|================================== | 53%
|
|=================================== | 53%
|
|=================================== | 54%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 57%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 74%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 76%
|
|================================================== | 77%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 80%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 82%
|
|====================================================== | 83%
|
|====================================================== | 84%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 86%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 91%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================= | 95%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 97%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
[1] "Scaling data matrix"
|
| | 0%
|
|=================================================================| 100%
tiss <- FindVariableGenes(object = tiss, do.plot = TRUE, x.high.cutoff = Inf, y.cutoff = 0.5)
Run Principal Component Analysis.
tiss <- RunPCA(object = tiss, do.print = FALSE)
tiss <- ProjectPCA(object = tiss, do.print = FALSE)
Later on (in FindClusters and TSNE) you will pick a number of principal components to use. This has the effect of keeping the major directions of variation in the data and, ideally, supressing noise. There is no correct answer to the number to use, but a decent rule of thumb is to go until the plot plateaus.
PCElbowPlot(object = tiss)
Choose the number of principal components to use.
# Set number of principal components.
n.pcs = 15
The clustering is performed based on a nearest neighbors graph. Cells that have similar expression will be joined together. The Louvain algorithm looks for groups of cells with high modularity–more connections within the group than between groups. The resolution parameter determines the scale…higher resolution will give more clusters, lower resolution will give fewer.
For the top-level clustering, aim to under-cluster instead of over-cluster. It will be easy to subset groups and further analyze them below.
# Set resolution
res.used <- 1.0
tiss <- FindClusters(object = tiss, reduction.type = "pca", dims.use = 1:n.pcs,
resolution = res.used, print.output = 0, save.SNN = TRUE)
To visualize
# If cells are too spread out, you can raise the perplexity. If you have few cells, try a lower perplexity (but never less than 10).
tiss <- RunTSNE(object = tiss, dims.use = 1:n.pcs, seed.use = 10, perplexity=30, dim.embed = 2)
# note that you can set do.label=T to help label individual clusters
TSNEPlot(object = tiss, do.label = T)
Check expression of genes of interset.
VlnPlot(tiss, genes_to_check)
Dotplots let you see the intensity of exppression and the fraction of cells expressing for each of your genes of interest.
How big are the clusters?
table(tiss@ident)
0 1 2 3 4 5 6 7 8 9
501 391 329 313 266 219 187 169 68 57
Which markers identify a specific cluster?
clust.markers <- FindMarkers(object = tiss, ident.1 = 2, ident.2 = 1, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
print(x = head(x= clust.markers, n = 10))
p_val avg_diff pct.1 pct.2
Dcn 1.905333e-316 3.298991 0.997 0.665
Plac9 1.298320e-298 3.112769 0.997 0.292
Col1a2 1.345735e-288 2.941688 1.000 0.708
Tmsb10 3.680076e-286 2.093490 1.000 0.964
Nbl1 8.008946e-268 2.908757 0.994 0.399
Col1a1 1.885544e-264 2.622059 1.000 0.614
Gsn 1.771160e-263 2.519395 1.000 0.992
Lgals1 4.033902e-259 2.831648 1.000 0.299
Col3a1 6.349244e-259 2.937657 0.997 0.455
Sparc 1.132132e-258 2.621723 1.000 0.716
You can also compute all markers for all clusters at once. This may take some time.
tiss.markers <- FindAllMarkers(object = tiss, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
Display the top markers you computed above.
tiss.markers %>% group_by(cluster) %>% top_n(25, avg_diff)
tiss= BuildClusterTree(tiss)
[1] "Finished averaging RNA for cluster 0"
[1] "Finished averaging RNA for cluster 1"
[1] "Finished averaging RNA for cluster 2"
[1] "Finished averaging RNA for cluster 3"
[1] "Finished averaging RNA for cluster 4"
[1] "Finished averaging RNA for cluster 5"
[1] "Finished averaging RNA for cluster 6"
[1] "Finished averaging RNA for cluster 7"
[1] "Finished averaging RNA for cluster 8"
[1] "Finished averaging RNA for cluster 9"
Node18_markers = FindAllMarkersNode(tiss, node = 18)
Node18_markers %>% group_by(cluster) %>% top_n(15, avg_diff)
At a coarse level, we can use canonical markers to match the unbiased clustering to known cell types:
# stash current cluster IDs
tiss <- StashIdent(object = tiss, save.name = "cluster.ids")
# enumerate current cluster IDs and the labels for them
cluster.ids <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
annotation <- c("mesenchymal cell", "bladder cell" , "mesenchymal cell", "bladder cell", "basal cell of urothelium", "bladder cell", "mesenchymal cell", "mesenchymal cell", "endothelial cell", "leukocyte")
cell_ontology_id <- c("CL:0008019", "CL:1001319" , "CL:0008019", "CL:1001319", "CL:1000486", "CL:1001319", "CL:0008019", "CL:0008019", "CL:0000115", "CL:0000738")
tiss@meta.data[,'annotation'] <- plyr::mapvalues(x = tiss@ident, from = cluster.ids, to = annotation)
tiss@meta.data[,'cell_ontology_id'] <- plyr::mapvalues(x = tiss@ident, from = cluster.ids, to = cell_ontology_id)
tiss@meta.data[tiss@cell.names,'annotation'] <- as.character(tiss@meta.data$annotation)
tiss@meta.data[tiss@cell.names,'cell_ontology_id'] <- as.character(tiss@meta.data$cell_ontology_id)
TSNEPlot(object = tiss, do.label = TRUE, pt.size = 0.5, group.by='annotation')
Color by metadata, like plate barcode, to check for batch effects.
TSNEPlot(object = tiss, do.return = TRUE, group.by = "channel")
TSNEPlot(object = tiss, do.return = TRUE, group.by = "mouse.sex")
Print a table showing the count of cells in each identity category from each plate.
table(as.character(tiss@ident), as.character(tiss@meta.data$channel))
10X_P4_3 10X_P4_4 10X_P7_7
0 30 454 17
1 20 212 159
2 40 278 11
3 28 248 37
4 10 204 52
5 6 198 15
6 9 116 62
7 0 2 167
8 3 45 20
9 3 26 28
table(as.character(tiss@ident), as.character(tiss@meta.data$mouse.id))
3-F-56 3-M-8 3-M-9
0 17 30 454
1 159 20 212
2 11 40 278
3 37 28 248
4 52 10 204
5 15 6 198
6 62 9 116
7 167 0 2
8 20 3 45
9 28 3 26
We can repeat the above analysis on a subset of cells, defined using cluster IDs or some other metadata. This is a good way to drill down and find substructure.
# Subset data based on cluster id
subtiss <- SubsetData(object = tiss, ident.use = c(3), do.center = F, do.scale = F, cells.use = )
# To subset data based on annotation or other metadata, you can explicitly pass cell names
cells.to.use = tiss@cell.names[which(tiss@meta.data$mouse.sex == 'F')]
subtiss <- SubsetData(object = tiss, cells.use = cells.to.use, do.center = F, do.scale = F)
subtiss <- NormalizeData(object = subtiss)
subtiss <- ScaleData(object = subtiss, vars.to.regress = c("nUMI", "percent.ribo","Rn45s"))
[1] "Regressing out nUMI" "Regressing out percent.ribo"
[3] "Regressing out Rn45s"
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 12%
|
|======== | 13%
|
|========= | 14%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 16%
|
|=========== | 17%
|
|=========== | 18%
|
|============ | 18%
|
|============ | 19%
|
|============= | 20%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 23%
|
|=============== | 24%
|
|================ | 24%
|
|================ | 25%
|
|================= | 26%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|===================== | 32%
|
|====================== | 33%
|
|====================== | 34%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 43%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 47%
|
|=============================== | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 51%
|
|================================== | 52%
|
|================================== | 53%
|
|=================================== | 53%
|
|=================================== | 54%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 57%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 74%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 76%
|
|================================================== | 77%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 80%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 82%
|
|====================================================== | 83%
|
|====================================================== | 84%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 86%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 91%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================= | 95%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 97%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
[1] "Scaling data matrix"
|
| | 0%
|
|=================================================================| 100%
Run Principal Component Analysis.
subtiss <- FindVariableGenes(object = subtiss, do.plot = TRUE, x.high.cutoff = Inf, y.cutoff = 0.8)
subtiss <- RunPCA(object = subtiss, pcs.compute = 20, weight.by.var = F)
[1] "PC1"
[1] "Mef2c" "Ctss" "Mrc1" "Lyz1" "Fcer1g" "H2-Eb1" "Tyrobp"
[8] "C1qb" "Tmsb4x" "C1qc" "Lrrc33" "H2-Aa" "C1qa" "Csf1r"
[15] "Laptm5" "Lyz2" "Ms4a7" "Sfpi1" "Pcp4l1" "Lyn" "Pld4"
[22] "Bcam" "Ly86" "Emr1" "Cd74" "Tinagl1" "Cd53" "Pf4"
[29] "C5ar1" "Lcp1"
[1] ""
[1] "Col3a1" "Col1a1" "Col1a2" "Dcn" "Mgp" "Serping1"
[7] "Rcn3" "Dkk3" "Sparc" "Fstl1" "Mmp2" "Rarres2"
[13] "Aebp1" "Cygb" "Pcolce" "Col5a2" "Fbln5" "Prelp"
[19] "Wnt2" "Plac8" "Vcan" "C1s" "Fn1" "Tcf21"
[25] "Col6a3" "Col6a2" "Igfbp6" "C1ra" "Thbs2" "Nupr1"
[1] ""
[1] ""
[1] "PC2"
[1] "Sparcl1" "Tm4sf1" "Pcp4l1" "Esam"
[5] "Timp3" "Epas1" "Cav1" "Prss23"
[9] "Sdpr" "Pecam1" "Emcn" "Eltd1"
[13] "Cdh5" "Podxl" "Ecscr" "Egfl7"
[17] "Gng11" "Jam2" "Slc9a3r2" "Flt1"
[21] "Sncg" "Gpr116" "Apold1" "Mmrn2"
[25] "Abcb1a" "Sorbs2" "Gimap6" "C130074G19Rik"
[29] "Utrn" "Prkcdbp"
[1] ""
[1] "H2-Aa" "H2-Ab1" "Cd83" "Tyrobp" "Ctss" "Lyz2" "Lyz1"
[8] "H2-Eb1" "Fcer1g" "Sfpi1" "H2-DMb1" "Cd74" "Laptm5" "Ly86"
[15] "Cd53" "Mrc1" "H2-DMa" "Cd52" "Pld4" "Plek" "Cybb"
[22] "C1qb" "Ms4a7" "Emr1" "C1qc" "C1qa" "Lilrb4" "Csf1r"
[29] "Bcl2a1b" "C5ar1"
[1] ""
[1] ""
[1] "PC3"
[1] "Cd34" "Cst3" "Fxyd5" "Scara5" "Pi16" "Clec3b" "Mfap5"
[8] "Srgn" "Emp3" "Sdpr" "Laptm5" "Krtdap" "Slc43a3" "Tyrobp"
[15] "Cd74" "Cd52" "Lbp" "Lum" "Lmo2" "Fcer1g" "Htra3"
[22] "H2-DMa" "H2-Eb1" "Igfbp4" "Fbln1" "Plbd1" "Rbp1" "Itih5"
[29] "Rac2" "H2-Aa"
[1] ""
[1] "Ly6d" "Wfdc2" "Aqp3" "Spint2"
[5] "Krt7" "Igfbp2" "Perp" "Krt15"
[9] "Krt19" "Sprr1a" "Cldn7" "Krt8"
[13] "Mal" "1110032A04Rik" "Cldn4" "Gsto1"
[17] "Upk1a" "Krt5" "Ezr" "Akr1b8"
[21] "Acaa1b" "Ctse" "Cdh1" "Krt23"
[25] "Vsig2" "Avpi1" "Aldh3a1" "Tacstd2"
[29] "Tpm2" "1600029D21Rik"
[1] ""
[1] ""
[1] "PC4"
[1] "Scara5" "Clec3b" "Pi16" "Mfap5" "Gsn"
[6] "Krtdap" "Lbp" "Lum" "Sfrp1" "Abi3bp"
[11] "Fbln1" "Cd55" "Entpd2" "Wfdc2" "Ccdc80"
[16] "Serpina3n" "Krt7" "Cldn7" "Htra3" "Perp"
[21] "Arap1" "Id2" "Ly6d" "Col8a1" "Krt19"
[26] "Npy1r" "Igfbp2" "Plxdc2" "Cdh1" "Tnxb"
[1] ""
[1] "Col4a2" "Col4a1" "Cd200" "Egfl7"
[5] "Ifi27l1" "Ptprb" "Gpr116" "Emcn"
[9] "Eltd1" "Tnc" "Pecam1" "Gimap6"
[13] "Car3" "Irf1" "Cdh5" "Cxcl12"
[17] "Flt1" "Podxl" "Gadd45b" "Cd93"
[21] "Mndal" "Arhgap31" "Ecscr" "Tsc22d1"
[25] "Mmrn2" "Ifi203" "C130074G19Rik" "Srgn"
[29] "Pltp" "Pde4b"
[1] ""
[1] ""
[1] "PC5"
[1] "Plvap" "Flt1" "Pcdh17" "Emcn"
[5] "Gpr116" "Eltd1" "Cdh5" "Rsad2"
[9] "Mmrn2" "Pecam1" "Ctla2a" "C130074G19Rik"
[13] "Podxl" "Egfl7" "Pde2a" "Igfbp3"
[17] "Scarb1" "Mal" "Gimap6" "Jam2"
[21] "Ptprb" "St3gal6" "Gpihbp1" "Aqp3"
[25] "Fam101b" "Krt7" "Vsig2" "S1pr1"
[29] "Wfdc2" "Cldn4"
[1] ""
[1] "Rcan2" "Nrip2" "ORF63" "Pln" "Des" "Myh11" "Ckb"
[8] "Cox4i2" "Pdlim3" "Filip1l" "Lmod1" "Crip1" "Rgs4" "Acta2"
[15] "Myl9" "Sncg" "Cald1" "Gucy1b3" "Mrvi1" "Mustn1" "Rrad"
[22] "Rgs5" "Aspn" "Bcr" "S100a4" "Gucy1a3" "Rasl11a" "Ltbp1"
[29] "Rbpms2" "Notch3"
[1] ""
[1] ""
subtiss <- ProjectPCA(object = subtiss, do.print = FALSE)
# If this fails for your subset, it may be that cells.use is more cells than you have left! Try reducing it.
PCHeatmap(object = subtiss, pc.use = 1:3, cells.use = 250, do.balanced = TRUE, label.columns = FALSE, num.genes = 12)
Later on (in FindClusters and TSNE) you will pick a number of principal components to use. This has the effect of keeping the major directions of variation in the data and, ideally, supressing noise. There is no correct answer to the number to use, but a decent rule of thumb is to go until the plot plateaus.
PCElbowPlot(object = subtiss)
Choose the number of principal components to use.
# Set number of principal components.
sub.n.pcs = 5
The clustering is performed based on a nearest neighbors graph. Cells that have similar expression will be joined together. The Louvain algorithm looks for groups of cells with high modularity–more connections within the group than between groups. The resolution parameter determines the scale…higher resolution will give more clusters, lower resolution will give fewer.
# Set resolution
sub.res.used <- 1
subtiss <- FindClusters(object = subtiss, reduction.type = "pca", dims.use = 1:sub.n.pcs,
resolution = sub.res.used, ,print.output = 0, save.SNN = TRUE)
To visualize
# If cells are too spread out, you can raise the perplexity. If you have few cells, try a lower perplexity (but never less than 10).
subtiss <- RunTSNE(object = subtiss, dims.use = 1:sub.n.pcs, seed.use = 10, perplexity=20)
# note that you can set do.label=T to help label individual clusters
TSNEPlot(object = subtiss, do.label = T)
subtiss.markers <- FindAllMarkers(object = subtiss, only.pos = TRUE, min.pct = 0.25, thresh.use = 0.25)
subtiss.markers %>% group_by(cluster) %>% top_n(6, avg_diff)
Check expression of genes of interset.
genes_to_check = c('Alb', 'Cyp2f2', 'Cyp2e1', 'Hamp', 'Glul', 'Ass1', 'Axin2', 'Igfbp2')
FeaturePlot(subtiss, genes_to_check, pt.size = 1)
Dotplots let you see the intensity of exppression and the fraction of cells expressing for each of your genes of interest.
# To change the y-axis to show raw counts, add use.raw = T.
DotPlot(subtiss, genes_to_check, plot.legend = T)
How big are the clusters?
table(subtiss@ident)
0 1 2 3 4 5 6
167 117 93 74 69 35 13
Color by metadata, like plate barcode, to check for batch effects.
TSNEPlot(object = subtiss, do.return = TRUE, group.by = "channel")
Print a table showing the count of cells in each identity category from each plate.
table(as.character(subtiss@ident), as.character(subtiss@meta.data$channel))
10X_P7_7
0 167
1 117
2 93
3 74
4 69
5 35
6 13
When you save the annotated tissue, please give it a name.
filename = here('00_data_ingest', '04_tissue_robj_generated',
paste0(tissue_of_interest, "_droplet_seurat_tiss.Robj"))
print(filename)
[1] "/Users/olgabot/code/tabula-muris/00_data_ingest/04_tissue_robj_generated/Bladder_droplet_seurat_tiss.Robj"
save(tiss, file=filename)
# To reload a saved object
# filename = here('00_data_ingest', '04_tissue_robj_generated',
# paste0(tissue_of_interest, "_seurat_tiss.Robj"))
# load(file=filename)
So that Biohub can easily combine all your annotations, please export them as a simple csv.
head(tiss@meta.data)
filename = here('00_data_ingest', '03_tissue_annotation_csv',
paste0(tissue_of_interest, "_droplet_annotation.csv"))
write.csv(tiss@meta.data[,c('channel','annotation','cell_ontology_id')], file=filename)